package com.xm.xmapp.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MyViewPager extends ViewPager {

	private boolean scrollble = true;
	public MyViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	public MyViewPager(Context context) {
		super(context);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int height = 0;
		for (int i = 0; i < getChildCount(); i++) {
			View child = getChildAt(i);
			if (child != null) {
				child.measure(widthMeasureSpec,
						MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
				int h = child.getMeasuredHeight();
				if (h > height) // 采用最大的view的高度。
					height = h;
			}
		}
		heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
				MeasureSpec.EXACTLY);
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (!scrollble) {
			return true;
		}
		return super.onTouchEvent(ev);
	}

	public boolean isScrollble() {
		return scrollble;
	}

	public void setScrollble(boolean scrollble) {
		this.scrollble = scrollble;
	}

	@Override
	public void setVisibility(int visibility) {

		super.setVisibility(visibility);

	}

	@Override
	protected void onDraw(Canvas arg0) {

		try {
			super.onDraw(arg0);
		} catch (Exception e) {

		}

	}

	@Override
	protected int getChildDrawingOrder(int childCount, int i) {
		try {
			return super.getChildDrawingOrder(childCount, i);
		} catch (Exception e) {
			return i;
		}
	}

	public static class MyOnPageChangeListener implements OnPageChangeListener {

		@Override
		public void onPageScrolled(int position, float positionOffset,
				int positionOffsetPixels) {
		}

		@Override
		public void onPageSelected(int position) {
		}

		@Override
		public void onPageScrollStateChanged(int state) {
		}
	}
}
